package com.cdtye.shuoh.config.websocket;

import com.cdtye.shuoh.config.websocket.event.MessageEvent;
import com.cdtye.shuoh.config.websocket.service.WebSocketSession;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.yeauty.pojo.Session;

@Component
@Slf4j
public class MessageEventListener4Push {
    @EventListener
    public void handleEvent(MessageEvent event) throws JsonProcessingException {
        System.out.println("向前台"+event.getDeviceId()+"发送消息"+event.getMsg());
        Session session = WebSocketSession.getSessionByClient(event.getDeviceId());
        if (null != session) {
            WebSocketSession.sendMessage2Target(session, event.getMsg());
        }
    }
}
